clear all
set more off
cd "/Users/yasenov/Dropbox (IPL)/RefugeeBan/data/"

***********
***********
***********

use "WRAPS/wraps_fips.dta"
keep if year >= 2015

merge 1:1 fips year using "crime/crime.dta", keep(1 3) keepusing(property violent clear*)
drop if _merge == 1   
drop _merge

merge 1:1 fips year using "demographics/demographics.dta", keep(1 3)
drop if _merge == 1   
drop _merge

tab year
recode year (2015=2016) (2018=2017)
tab year

gen lproperty_crime = log(property_crime + 1)
gen rproperty_crime = (property_crime / pop_total) * 100000

gen lviolent_crime = log(violent_crime + 1)
gen rviolent_crime = (violent_crime / pop_total) * 100000

gen lrefugees = log(refugees + 1)
gen rrefugees = (refugee / pop_total) * 100

gen s_movers = (pop_moved_in_1_yr_ago / pop_total) * 100000
gen l_movers = log(pop_moved_in_1_yr_ago+1)

gen s_clr_property = cleared_property_crime / property_crime
gen s_clr_violent = cleared_violent_crime / violent_crime

local vars lproperty rproperty rviolent lviolent rrefugees lrefugees pop_total pop_density s_black s_hisp s_hs_dropout s_unempl s_not_in_lf s_white s_police_male s_movers s_hs_grad s_male_age_15_34 l_movers s_clr_property s_clr_violent
collapse (mean) `vars', by(year fips)

sum

reshape wide `vars', i(fips) j(year)

gen d_rproperty_crime = rproperty_crime2017 - rproperty_crime2016
gen d_rviolent_crime = rviolent_crime2017 - rviolent_crime2016
gen d_rrefugees = (rrefugees2017 - rrefugees2016) // * 100         // careful!!

gen d_lproperty_crime = lproperty_crime2017 - lproperty_crime2016
gen d_lviolent_crime = lviolent_crime2017 - lviolent_crime2016
gen d_lrefugees = lrefugees2017 - lrefugees2016

gen d_s_movers = s_movers2017 - s_movers2016
gen d_l_movers = l_movers2017 - l_movers2016

gen d_s_police_male = s_police_male2017 - s_police_male2016

gen d_s_clr_property = s_clr_property2017 - s_clr_property2016
gen d_s_clr_violent = s_clr_violent2017 - s_clr_violent2016

gen county_fips = substr(fips, 3, 3)
gen state_fips = substr(fips, 1, 2)

replace pop_total2016 = log(pop_total2016)
*replace pop_density2016 = log(pop_density2016)

drop *2017


label var d_rrefugees "$\Delta$\text{refugees per capita$^{\text{pre-post}}$}"
label var d_lrefugees "$\Delta$\text{log(refugees)}$^{\text{pre-post}}$"


global if1 if abs(d_rproperty) <= 1000 
global if2 if abs(d_rviolent) <= 1000 
global if3 if abs(d_lproperty) <= 1 
global if4 if abs(d_lviolent) <= 1

**************
************** MAIN SPECIFICATION
**************

global options cluster(state_fips) 
global weight 
global controls 

eststo clear
eststo: reg d_rproperty d_rrefugees $controls $if1 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rproperty d_rrefugees $controls $if1 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_rviolent d_rrefugees $controls $if2 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rviolent d_rrefugees $controls $if2 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_lproperty d_lrefugees $controls $if3 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lproperty d_lrefugees $controls $if3 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_lviolent d_lrefugees $controls $if4 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lviolent d_lrefugees $controls $if4 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
	
esttab using "../results/tab_d2016_17.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
	
	
**************
************** ADDING CONTROLS
**************	

global options cluster(state_fips)
global weight
global controls pop_total s_black s_white s_hisp s_hs_dropout s_hs_grad s_unempl s_not_in_lf s_male_age_15_34

eststo clear
eststo: reg d_rproperty d_rrefugees $controls $if1 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rproperty d_rrefugees $controls $if1 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_rviolent d_rrefugees $controls $if2 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rviolent d_rrefugees $controls $if2 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_lproperty d_lrefugees $controls $if3 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lproperty d_lrefugees $controls $if3 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_lviolent d_lrefugees $controls $if4 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lviolent d_lrefugees $controls $if4 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	

esttab using "../results/tab_d2016_17_controls.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
	
**************
************** WIHTOUT DROPPING OUTLIERS
**************

global options cluster(state_fips)
global weight 
global controls 

eststo clear
eststo: reg d_rproperty d_rrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rproperty d_rrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_rviolent d_rrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rviolent d_rrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_lproperty d_lrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lproperty d_lrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_lviolent d_lrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lviolent d_lrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
	
esttab using "../results/tab_d2016_17_no_dropping.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
	
**************
************** WEIGHTED REGRESSIONS
**************	

global weight [aw = pop_total2016]
global options cluster(state_fips)
global controls 

eststo clear
eststo: reg d_rproperty d_rrefugees $controls $if1 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rproperty d_rrefugees $controls $if1 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_rviolent d_rrefugees $controls $if2 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_rviolent d_rrefugees $controls $if2 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_lproperty d_lrefugees $controls $if3 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lproperty d_lrefugees $controls $if3 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm
eststo: reg d_lviolent d_lrefugees $controls $if4 $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_lviolent d_lrefugees $controls $if4 $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	mgroups("Crime Rates" "Logs Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
	
esttab using "../results/tab_d2016_17_weighted.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Property" "Property" "Violent" "Violent" "Property" "Property" "Violent" "Violent") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Crime Rates" "Log Number of Crimes", pattern(1 0 0 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
	

**************
************** SHARE MALE POLICE
**************	

global weight 
global options cluster(state_fips)
global controls 

eststo clear
eststo: reg d_s_police_male d_rrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_s_police_male d_rrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_s_police_male d_lrefugees $controls  $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_s_police_male d_lrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Share Male Police" "Share Male Police" "Share Male Police" "Share Male Police") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_d2016_17_share_male_police.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Share Male Police" "Share Male Police" "Share Male Police" "Share Male Police") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Rates" "Log", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 

	
**************
************** SHARE MOVERS
**************	

global weight 
global options cluster(state_fips)
global controls 

eststo clear
eststo: reg d_s_movers d_rrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_s_movers d_rrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_l_movers d_lrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_l_movers d_lrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("$\Delta$ Share In-movers" "Share In-movers" "\% $\Delta$ In-movers" "\% $\Delta$ In-movers") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_d2016_17_share_movers.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("$\Delta$ Share In-movers" "$\Delta$ Share In-movers" "\% $\Delta$ In-movers" "\% $\Delta$ In-movers") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Rates" "Log", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
			

**************
************** SHARE CLEARED CRIMES
**************	

global weight 
global options cluster(state_fips)
global controls 

eststo clear
eststo: reg d_s_clr_property d_rrefugees $controls $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_s_clr_property d_rrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

eststo: reg d_s_clr_violent d_lrefugees $controls  $weight, $options
estadd local stateFE ""
estadd ysumm
eststo: areg d_s_clr_violent d_lrefugees $controls $weight, $options absorb(state_fips)
estadd local stateFE "X"
estadd ysumm

esttab, label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Share Cleared Property" "Share Cleared Property" "Share Cleared Violent" "Share Cleared Violent") ///
	mgroups("Rates" "Logs", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	scalars("stateFE State Fixed Effects") ///
	star(* 0.05 ** 0.01 *** 0.001) 
	
esttab using "../results/tab_d2016_17_share_clr_crime.tex", replace label ///
	keep(d_rrefugees d_lrefugees) b(%4.3f) se(%4.3f) ///
	mtitles("Share Cleared Property" "Share Cleared Property" "Share Cleared Violent" "Share Cleared Violent") ///
	scalars("stateFE State Fixed Effects") ///
	mgroups("Rates" "Log", pattern(1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(})span erepeat(\cmidrule(lr){@span})) ///
	star(* 0.05 ** 0.01 *** 0.001) nonotes ///
	stats(stateFE N r2 , label("State FE" "N" "R$^2$") fmt(%4.3f %3.0f %4.3f %4.3f))   // ymean ysd "$\bar{Y}$" "sd(Y)" 
			
